/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package biofilter.records;

import biofilter.exceptions.InvalidRecordException;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.io.*;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import static org.junit.Assert.*;
import biofilter.sources.EMBLRecordsSource;
import biofilter.data.Sequence.*;
import biofilter.records.emblxsd.*;

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader; 
import java.io.OutputStreamWriter;
import java.io.Writer;
import java.net.MalformedURLException;
import java.net.URL;

import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;
import javax.xml.bind.Unmarshaller;



import org.apache.velocity.VelocityContext;
import org.apache.velocity.app.VelocityEngine;

import com.hp.hpl.jena.rdf.model.Model;
import com.hp.hpl.jena.rdf.model.ModelFactory;

/**
 *
 * @author Daniel Quest
 * @date   Jan 12 2009
 */
public class EMBLRecordTest {

    public EMBLRecordTest() {
    }

    @BeforeClass
    public static void setUpClass() throws Exception {
    }

    @AfterClass
    public static void tearDownClass() throws Exception {
    }
    EMBLRecord instance = null;
    EMBLRecord xmlinstance = null;
    @Before
    public void setUp() {
        try {
            String emblFile = "test/testdata/embl/multiEMBLexample.embl";
            EMBLRecordsSource ers = new EMBLRecordsSource(emblFile);
            String expResult = "";
            this.instance = (EMBLRecord) ers.getRecord();
            init();
        } catch (InvalidRecordException ex) {
            Logger.getLogger(EMBLRecordTest.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    @After
    public void tearDown() {
    }
    
    public void init(){
         //get the xml file input and unmarshall it to objects
        try {
            //String curDir = System.getProperty("user.dir");
            //System.err.println(curDir);
            //Here we populate the java objects with XML data.
            //String xmlFile = "file://localhost/"+curDir+"/test/testdata/embl/multiEMBLexample.xml"; //it will be 2 records actually...
            //get the xml file input
            //URL xmlFileUrl = new URL(xmlFile);
            //InputStream xmlFileInputStream;
            //xmlFileInputStream = xmlFileUrl.openStream();

            JAXBContext jc = JAXBContext.newInstance("biofilter.records.emblxsd"); 
            //unmarshal the information from xml
            Unmarshaller unmarshaller = jc.createUnmarshaller();

            EMBLServices embls = (EMBLServices) unmarshaller.unmarshal(new File("test/testdata/embl/multiEMBLexample.xml"));
            xmlinstance = new EMBLRecord();
            xmlinstance.setEMBLServices(embls);
        } catch (JAXBException ex) {
                Logger.getLogger(EMBLRecordTest.class.getName()).log(Level.SEVERE, null, ex);
        }
         
      
    }

    /**
     * Test of get method, of class EMBLRecord.
     */
    @Test
    public void testGetSequence() {
        System.out.println("getSequence");
        String expResult = "atgaaacacagaaaacttagtcttaccttagccgtaggacttctatcaactacaatgacagcacaaaaagcactacaacttaacaagaaaaatatcgatgaagtcattgccgctatgacattagaagagaaggcacaacttctcgttggtgttgggcatcaggatttcgtaggttctggaactatgctcggacaacattcacgccttgttgccggtgcagccggacagacagcagaaatctcacgcctcggcatccctgcaacagtcgttgcagatggtcctgcaggtgttcacataaatcctacccgaccaggaacaaatcaaacattttatgcaacaggtttccctatcggtacatgtttggcatctacttggaacactgatttggtttatcatgtaggaaaagccataggaaacgagactttggaatatggcatcgatgttatcctgggtcctggtatgaacttacaccgcagtccgctctgtggacgcaacttcgaatattatagtgaagatcctattgtcacaggtctcattggttctgccatggtaaaaggtatccaaagccaaggcgttggagttagtgcaaaacactttgctgccaactcacaagaaagtgaccgtacccgtgtcgatgagcgcatctctcagcgtgcactccgtgaattatatctcaaaggattcgagatcatggttcgcgacagcaagccttggaccttgatgtcatcttacaacaagattaatggtacatatacccaaggcagcaaagacttgctcaccaacatccttcgtaaagactgggggtaccaaggtatcgtcatgaccgactggatcggtgaacgtgcagatctccctgtagagacagaagtagaagctggcaacgacttcatgatgccaggaaatgcagatcgggcaaagcacatcgtaaaagcagtcaaagctggtcgcctcgacataaaggatgttgcccgcaacatcaagaatatgcttgagtacattctcaagactcctcgttacaagaaatacaaatacaccaaccaaccagacctgaaggcacacgcacagatcacacgtcaggcttcaacagaaggtatggttctcctaaagaacgataacaacgttcttcctgtcaagaacatgaagaaagttgccctattcggtgttaactcatacgattttctcagcggtggtcttggttccggttgcgtcaatgtcccttatgttgtcgacatggttcatggactacagaatgcaggtattgcgacaaccaaacagctcaccgagatttacgagaactacgtaaaatatgccaaggctaagctacaggcagacaagaatccagagatgtggttcttggatcagggacagccaaagctcgacgagatcgagattactcagcgctgtgtagagcacgaagttggtgatgccgacgcagccatcatcacgatagctcgtcaggcaggtgaaggaatggaccgttccatcgaaggagagttcaaccttacagatcatgagaaagccatgatttctcgtgtcagcgatgttttccatgccaacaacaaacccgttattgtcatcatcaactctggtagtgtcatggagacagcctcttggcgtgaccgtgttgatgccattctcgttgcatggcagccaggtgaagaaggtggtaatagtgtagccgatgttcttatcggtaaggcaaacccttcaggccacctcaccagcacatggcctatcagcgctgcagatgttccttctaccaagaatttcccacaacagccagcttactataacctatccgacaaactctatagcaacaacatgaaaggtgtcaactacacaaaccacgaagaagatatctacgtaggctatcgctatttcgataccttcaacaaaaaggttgcttatccatttggttatggtcttagttacaccaccttcgaattcggtaaaccttcagtatctctgaatggtgacaagattacagttacagtttctgtcaagaacataggaaaggttgcaggcaaacaggttgctcaggtttatgtaaaggctcctaagggtgcttatgagaaaccatcttgcgagttgaaagcctttgctaagaccaagaacctgaaacctggtcagagcgaaactttgaagatgatcatcgctaagcgcgacttagcaagtttcgacgaagccaacagtcagtggaaggttgatgccgggaaatacgaattctgtgttggcgacaacgtagaaagcatcaaaggtacagccagtcttaacttgtcagaatacacagagaagactaccaattcacttcctttgaacacgaagatgaatttacttcatcagtaa";
        BioSequence bios = xmlinstance.getSequence();
        String result = bios.get();
        assertEquals(expResult, result);
    }

    @Test
    public void testGetID(){
        System.out.println("getID");
        String expResult = "ID   X56734; SV 1; linear; mRNA; STD; PLN; 1859 BP.";
        //String result = instance.getID();
        //System.out.println(result);
        //assertEquals(expResult, result);
    }



}